package com.framework.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.DeptDao;
import com.framework.entity.sys.SysDept;
import com.framework.exception.RRException;
import com.framework.exception.menu.RespCode;
import com.framework.service.DeptService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wq
 */
@Service("deptService")
public class DeptServiceImpl extends ServiceImpl<DeptDao, SysDept> implements DeptService {

	@Override
	public SysDept queryDeptById(Long deptId) {
		if(deptId == null || deptId == 0){
			throw new RRException(RespCode.NOT_PARAM_ERROR);
		}
		SysDept sysDept = new SysDept();
		sysDept.setDeptId(deptId);
		return baseMapper.selectOne(sysDept);
	}

	@Override
	public List<SysDept> getDeptListExcept(Long[] deptIds) {
		List<SysDept> depts = selectList(new EntityWrapper<SysDept>().eq("del_flag", 0));

		//去除的列表
        List<Long> exceptDepts= Arrays.asList(deptIds);

        List<SysDept> sysDepts = depts.stream()
                .filter(e ->!exceptDepts.stream().anyMatch(e2 -> e2.equals(e.getDeptId())))
                .collect(Collectors.toList());

        return sysDepts;
	}

}
